package edu.hawaii.ics314.ical.model;

import java.util.Objects;

import edu.hawaii.ics314.ical.model.CalendarComponent.ComponentPriority;


public class CalendarComponentInfo {
	
	public CalendarComponentInfo() {
		// Do nothing.
	}
	
	public CalendarComponentInfo(CalendarComponent copySrc) {
		Objects.requireNonNull(copySrc);
		hostCalendar = copySrc.hostCalendar;
		classification = copySrc.classification;
		location = copySrc.location;
		priority = copySrc.priority;
		summary = copySrc.summary;
		startDateTime = copySrc.startDateTime;
		endDateTime = copySrc.endDateTime;
		timeZone = copySrc.timeZone;
		// Do not copy unrecognized properties, as they are not necessarily applicable to all calendar components.
	}
	
	public Calendar hostCalendar = null;
	
	public Property<String> classification = null;
	
	public Property<String> location = null;
	
	public Property<ComponentPriority> priority = null;
	
	public Property<String> summary = null;
	
	public Property<DateTime> startDateTime = null;
	
	public Property<DateTime> endDateTime = null;
	
	public Property<TimeZone> timeZone = null;
	
	public Property<?>[] unrecognizedProperties = null;
	
	@Override
	public boolean equals(Object other) {
		if(other instanceof CalendarComponentInfo) {
			CalendarComponentInfo otherInfo = (CalendarComponentInfo) other;
			return isNullOrEqual(hostCalendar, otherInfo.hostCalendar)
					&& isNullOrEqual(classification, otherInfo.classification)
					&& isNullOrEqual(location, otherInfo.location)
					&& isNullOrEqual(priority, otherInfo.priority)
					&& isNullOrEqual(summary, otherInfo.summary)
					&& isNullOrEqual(startDateTime, otherInfo.startDateTime)
					&& isNullOrEqual(endDateTime, otherInfo.endDateTime)
					&& isNullOrEqual(timeZone, otherInfo.timeZone);
		} else {
			return false;
		}
	}
	
	private boolean isNullOrEqual(Object first, Object second) {
		return (first == null ? second == null : first.equals(second));
	}
	
}
